<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" draggable :show-fullscreen="true" :width="500" destroy-on-close @closed="$emit('closed')">
        <el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="120px" label-position="left">

            <el-form-item label="账号" prop="username">
                <el-input  v-model="form.username" clearable></el-input>
        	</el-form-item>
            <el-form-item label="密码" prop="password">
                <el-input  v-model="form.password" clearable></el-input>
        	</el-form-item>
            <el-form-item label="售后站点名称" prop="nickname">
                <el-input  v-model="form.nickname" clearable></el-input>
        	</el-form-item>
            <el-form-item label="真实名" prop="name">
                <el-input  v-model="form.name" clearable></el-input>
        	</el-form-item>
            <el-form-item label="手机号" prop="mobile">
                <el-input  v-model="form.mobile" clearable></el-input>
        	</el-form-item>
            <!-- <el-form-item label="运营中心" prop="run_id">
                <el-input-number :disabled="true" v-model="form.run_id"></el-input-number>
        	</el-form-item> -->
     
            
<!--           
            <el-form-item label="联系住址" prop="address">
                <el-input :disabled="true" v-model="form.address" clearable></el-input>
        	</el-form-item>
            <el-form-item label="身份证正面" prop="sfz1_image">
                <sc-upload :disabled="true" v-model="form.sfz1_image" icon="el-icon-picture-outline"></sc-upload>
        	</el-form-item>
            <el-form-item label="身份证反面" prop="sfz2_image">
                <sc-upload :disabled="true" v-model="form.sfz2_image" icon="el-icon-picture-outline"></sc-upload>
        	</el-form-item>
            <el-form-item label="人像照" prop="sfz3_image">
                <sc-upload :disabled="true" v-model="form.sfz3_image" icon="el-icon-picture-outline"></sc-upload>
        	</el-form-item>
            <el-form-item label="实名状态" prop="real_status">
                <el-switch v-model="form.real_status" :active-value="1" :inactive-value="0"></el-switch>
        	</el-form-item>
            <el-form-item label="头像" prop="avatar">
                <sc-upload :disabled="true" v-model="form.avatar" icon="el-icon-picture-outline"></sc-upload>
        	</el-form-item>
            <el-form-item label="等级" prop="level">
                <el-input-number :disabled="true" v-model="form.level"></el-input-number>
        	</el-form-item>
            <el-form-item label="性别" prop="gender">
                <el-input-number :disabled="true" v-model="form.gender"></el-input-number>
        	</el-form-item>
            <el-form-item label="生日" prop="birthday">
                <el-date-picker :disabled="true" v-model="form.birthday" type="datetime"></el-date-picker>
        	</el-form-item>
            <el-form-item label="格言" prop="bio">
                <el-input :disabled="true" v-model="form.bio" clearable></el-input>
        	</el-form-item>
            <el-form-item label="余额" prop="money">
                <el-input-number :disabled="true" v-model="form.money"></el-input-number>
        	</el-form-item>
            <el-form-item label="贝壳" prop="shell">
                <el-input-number :disabled="true" v-model="form.shell"></el-input-number>
        	</el-form-item>
            <el-form-item label="保证金" prop="surety">
                <el-input-number :disabled="true" v-model="form.surety"></el-input-number>
        	</el-form-item>
            <el-form-item label="邀请成功总积分" prop="share_score">
                <el-input-number :disabled="true" v-model="form.share_score"></el-input-number>
        	</el-form-item>
            <el-form-item label="积分" prop="score">
                <el-input-number :disabled="true" v-model="form.score"></el-input-number>
        	</el-form-item>
            <el-form-item label="加入IP" prop="joinip">
                <el-input :disabled="true" v-model="form.joinip" clearable></el-input>
        	</el-form-item>
            <el-form-item label="加入时间" prop="jointime">
                <el-date-picker :disabled="true" v-model="form.jointime" type="datetime"></el-date-picker>
        	</el-form-item> -->
<!--      
            <el-form-item label="Token" prop="token">
                <el-input :disabled="true" v-model="form.token" clearable></el-input>
        	</el-form-item>
            <el-form-item label="状态" prop="status">
                <el-radio v-model="form.status" v-for="(item,index) in status_option" :key="index" :label="index">{{item}}</el-radio>
        	</el-form-item>
            <el-form-item label="验证" prop="verification">
                <el-input :disabled="true" v-model="form.verification" clearable></el-input>
        	</el-form-item> -->
            <!-- <el-form-item label="上级id" prop="pid">
                <el-input-number :disabled="true" v-model="form.pid"></el-input-number>
        	</el-form-item> -->
            <!-- <el-form-item label="变更前上级" prop="before_pid">
                <el-input-number :disabled="true" v-model="form.before_pid"></el-input-number>
        	</el-form-item>
            <el-form-item label="原上级" prop="old_pid">
                <el-input-number :disabled="true" v-model="form.old_pid"></el-input-number>
        	</el-form-item> -->
            <!-- <el-form-item label="密码" prop="cipher">
                <el-input :disabled="true" v-model="form.cipher" clearable></el-input>
        	</el-form-item> -->
            <!-- <el-form-item label="二维码" prop="qr">
                <el-image :disabled="true" :src="form.qr" style="width: 80px; height: 80px" v-model="form.qr" clearable></el-image>
        	</el-form-item>
            <el-form-item label="邀请码" prop="invite_code">
                <el-input :disabled="true" v-model="form.invite_code" clearable></el-input>
        	</el-form-item> -->
        
            <!-- <el-form-item label="默认地址" prop="addr_id">
                <el-input-number :disabled="true" v-model="form.addr_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="角色ID" prop="set_id">
                <el-input-number :disabled="true" v-model="form.set_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="技能介绍" prop="skill">
                <el-input :disabled="true" v-model="form.skill" clearable></el-input>
        	</el-form-item>
            <el-form-item label="省id" prop="province_id">
                <el-input-number :disabled="true" v-model="form.province_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="城市id" prop="city_id">
                <el-input-number :disabled="true" v-model="form.city_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="区id" prop="district_id">
                <el-input-number :disabled="true" v-model="form.district_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="乡镇id" prop="town_id">
                <el-input-number :disabled="true" v-model="form.town_id"></el-input-number>
        	</el-form-item>
            <el-form-item label="支付密码" prop="pay_password">
                <el-input :disabled="true" v-model="form.pay_password" clearable></el-input>
        	</el-form-item>
            <el-form-item label="开放平台" prop="unionid">
                <el-input :disabled="true" v-model="form.unionid" clearable></el-input>
        	</el-form-item>
            <el-form-item label="微信真实姓名" prop="wechat_name">
                <el-input :disabled="true" v-model="form.wechat_name" clearable></el-input>
        	</el-form-item>
            <el-form-item label="微信openid" prop="wechat_openid">
                <el-input :disabled="true" v-model="form.wechat_openid" clearable></el-input>
        	</el-form-item>
            <el-form-item label="售后站服务用户id" prop="after_sales_user_id">
                <el-input-number :disabled="true" v-model="form.after_sales_user_id"></el-input-number>
        	</el-form-item> -->
        </el-form>
        <template #footer>
            <el-button @click="visible=false" >取 消</el-button>
            <el-button v-if="mode!='read'" type="primary" :loading="isSaveing" @click="submit()">注 册</el-button>
        </template>
    </el-dialog>
</template>

<script>
    
    export default {
        emits: ['success', 'closed'],
        
        data() {
            return {
                mode: "create",
                titleMap: {
                    read: '查看',
                    create: '新增',
                    update: '编辑',
                },
                visible: false,
                isSaveing: false,
                form: {
                    id: 0,
					username: '',
					nickname: '',
					name: '',
					mobile: '',
					password: '',
		
                },
                rules: {
                },
				real_status_option:{"0":"待认证","1":"已实名"},
				status_option:{"0":"关闭","normal":"正常"},
            }
        },
        methods: {
            open(mode='create2'){
                this.mode = mode;
                this.visible = true;
                return this
            },
            submit(){
                this.$refs.dialogForm.validate(async (valid) => {
                    if (valid) {
                        this.isSaveing = true;
                        var res = await this.$API.fa_user[this.mode].post(this.form);
                        this.isSaveing = false;
                        if(res.code == 200){
                            this.$emit('success', this.form, this.mode)
                            this.visible = false;
                            this.$message.success(res.message)
                        }else{
                            this.$alert(res.message, "提示", {type: 'error'})
                        }
                    }else{
                        return false;
                    }
                })
            },
            setData(data){
                this.$TABLE.assign(this,data);
            }
        }
    }
</script>